package view.icons
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	import model.vo.ViewVO;

	public class ColapseExpandIconView extends Sprite
	{
		private var expanded:Boolean;
		
		private var viewData:ViewVO;
		
		private var iconStroke:Number;
		
		private var iconColor:int;
		private var iconOverColor:int;
		private var iconSelectedColor:int;
		
		private var vectorArt:Array;
		
		public function ColapseExpandIconView()
		{
		}
		
		public function init( viewVO:ViewVO ):void
		{
			viewData = viewVO;
			
			setColapseExpandIconProperties();
			buildColapseExpandIcon();
		}
		
		public function colapseExpand():void
		{
			expanded = !expanded;
			
			if( expanded ) this.rotation = 45;
			else this.rotation = 0;
			
			paint();
		}
		
		public function select():void
		{
			iconColor = viewData.labelSelectedColor;
		}
		
		public function unselect():void
		{
			iconColor = viewData.labelColor;
			
			expanded = false;
			this.rotation = 0;
			paint();
		}
		
		private function setColapseExpandIconProperties():void
		{
			iconStroke = viewData.frameWeight;
			
			iconColor = viewData.labelColor;
			iconOverColor = viewData.labelOverColor;
			iconSelectedColor = viewData.labelSelectedColor;
		}
		
		private function buildColapseExpandIcon():void
		{
			vectorArt = ART.colapseExpandArt();
			
			paint();
		}
		private function paint():void
		{
			var g:Graphics = this.graphics;
			
			g.clear();
			
			if( expanded ) g.beginFill( iconSelectedColor, 1 );
			else g.beginFill( iconColor, 1 );
			g.moveTo( vectorArt[0][0], vectorArt[0][1] );
			var i:uint;
			for( i = 1; i < vectorArt.length; i++ )
				g.lineTo(vectorArt[i][0], vectorArt[i][1] );
			
			if( expanded ) g.endFill();
			
			
		}
		
		public function get isExpanded():Boolean
		{
			return expanded;
		}
	}
}